package org.jeecgframework.web.material.service.impl;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.material.service.HomeServiceI;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("homeService")
@Transactional
public class HomeServiceImpl extends CommonServiceImpl implements HomeServiceI {

	@Override
	public Map statisticSum() {
	    String sql_store = "select sum(amount) sum_store from product_store";
	    String sql_customer = "select count(*) count_customer from customer";
	    String sql_income = "select sum(paid) sum_income from flow ";
	    String sql_payout = "select sum(pay_out) sum_payout from flow ";
	    
	    BigDecimal sum_store = (BigDecimal) getValue(this.findOneForJdbc(sql_store), "sum_store");
	    Long count_customer = (Long) getValue(this.findOneForJdbc(sql_customer), "count_customer");
	    Double sum_income = (Double) getValue(this.findOneForJdbc(sql_income), "sum_income");
	    Double sum_payout = (Double) getValue(this.findOneForJdbc(sql_payout), "sum_payout");
	    
	    HashMap<String, Object> map_ret  = new  HashMap<String, Object>();
	    map_ret.put("sum_store", sum_store);
	    map_ret.put("count_customer", count_customer);
	    map_ret.put("sum_income", sum_income);
	    map_ret.put("sum_payout", sum_payout);
		return map_ret;
	}
	
	public Object getValue(Map<String, Object> map, String key){
		
		return	map.get(key);
		
	}

}